<?php
/**
 * This is the template for action id `create`.
 */

/** @var yii\web\View $this */
/** @var \console\gii\controller\Generator $generator */
/** @var string $actionCamelID */
/** @var string $controllerName */
/** @var string $modelName */

$modelName = $generator->modelName;
?>
        if ($this->isPost) {
            $model = new <?= $modelName ?>();
            $model->setScenario('<?= $modelName ?>_<?= $actionCamelID ?>');
            $model->load($this->post);
            if ($model->save()) {
                return $this->asOk('添加成功' . "#{$model->id}");
            }

            return $this->asFail($model->error);
        } else {
            return FormBuilder::instance(['id' => '<?= $generator->controllerCamelID ?>_<?= $actionCamelID ?>'])
                ->setPartial()
                ->setRequiredStyle()
                ->setTitle('新增<?= $generator->sourceName ?>')
                ->setFormControl([
                    'status' => $this->formControl->sw()->label('状态')->required(),
                    'sort' => $this->formControl->number()->label('排序')->required(),
                ])
                ->setCloseBtn()
                ->setSubmitBtn()
                ->setAutoClose()
                ->setSubmittedCalls([
                    'parent' => ['<?= $generator->controllerCamelID ?>_View'],
                ])
                ->render();
        }
